package com.sitanyun.merchant.guide.frament.model.impl;

import com.google.gson.Gson;
import com.sitanyun.merchant.guide.bean.AccountBean;
import com.sitanyun.merchant.guide.bean.RealNameBean;
import com.sitanyun.merchant.guide.callback.StringCallbacks;
import com.sitanyun.merchant.guide.frament.model.inter.IRealNameAModel;
import com.sitanyun.merchant.guide.presenter.callback.CallBack;
import com.sitanyun.merchant.guide.url.Urls;
import com.sitanyun.merchant.guide.weiht.SharedPreferenceUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.HashMap;

import okhttp3.Call;
import okhttp3.MediaType;

/**
 * 实名
 */
public class RealNameAModelImpl implements IRealNameAModel {
    @Override
    public <T> void setrealname(String staffId, String name, String idNum, String idPicFront, String idPicBack, CallBack callBack) {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("staffId",staffId);
        hashMap.put("name", name);
        hashMap.put("idNum", idNum);//文件名
        hashMap.put("idPicFront",idPicFront );//后缀
        hashMap.put("idPicBack",  idPicBack);//文件大小
        OkHttpUtils.postString()
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .addHeader("Content-Type", "application/json")
                .addHeader("Authorization", "Bearer " + SharedPreferenceUtil.getStringData("token"))
                .url(Urls.interest)
                .content(new Gson().toJson(hashMap))
                .build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {
            }
            @Override
            public void onResponse(String response, int id) {
                RealNameBean baseEntity= new Gson().fromJson(response, RealNameBean.class);
                callBack.onSuccess(baseEntity);
            }
        });

    }

    /**
     *
     * @param individualId
     * @param realname
     * @param certNo
     * @param callBack
     * @param <T>
     */
    @Override
    public <T> void setaccountIdentity(String individualId, String realname, String certNo, CallBack callBack) {
        OkHttpUtils.get().url(Urls.accountIdentity)
                .addHeader("Content-Type", "application/json")
                .addHeader("Authorization", "Bearer " + SharedPreferenceUtil.getStringData("token"))
                .addParams("individualId",individualId)
                .addParams("realname",realname)
                .addParams("certNo",certNo).build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                AccountBean baseEntity  = new Gson().fromJson(response, AccountBean.class);
             callBack.onSuccess(baseEntity);
            }
        });
    }


    @Override
    public <T> void setuserSign(String individualId, String accountId, CallBack callBack) {
        OkHttpUtils.get().url(Urls.userSign)
                .addHeader("Content-Type", "application/json")
                .addHeader("Authorization", "Bearer " + SharedPreferenceUtil.getStringData("token"))
                .addParams("individualId",individualId)
                .addParams("accountId",accountId).build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                AccountBean baseEntity  = new Gson().fromJson(response, AccountBean.class);
                callBack.onSuccess(baseEntity);
            }
        });
    }
}
